package com.warm.mini.wework.controller;

import com.alibaba.fastjson.JSONObject;
import com.warm.mini.wework.config.TanzsayConfig;
import com.warm.mini.wework.config.WeworkConfigProperties;
import com.warm.mini.wework.feign.WeworkApiRest;
import com.warm.mini.wework.service.invoke.AccessTokenServiceImpl;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description
 * @Author warmchuang
 * @Date 2022/2/7 15:09
 */
@RestController
@RequestMapping(value = "/")
public class TestController {

    @Resource
    private TanzsayConfig tanzsayConfig;
    @Resource
    private AccessTokenServiceImpl accessTokenService;

    @RequestMapping("health")
    public String health(){
        return "success";
    }

    @RequestMapping("accessToken")
    public String accessToken(){
        WeworkConfigProperties config = tanzsayConfig.contactConfig();
        return accessTokenService.getAccessToken(config);
    }

    @RequestMapping("userGet")
    public JSONObject userGet(@RequestParam("userId") String userId){
        WeworkConfigProperties config = tanzsayConfig.contactConfig();
        String accessToken = accessTokenService.getAccessToken(config);
        return WeworkApiRest.get().userGet(accessToken, userId);
    }
}
